Skip to content

feat: enable openai provider use aws profile#2230

Merged
JackYPCOnline merged 6 commits intostrands-agents:mainfrom
JackYPCOnline:feature/openai
May 1, 2026
Merged

feat: enable openai provider use aws profile#2230
JackYPCOnline merged 6 commits intostrands-agents:mainfrom
JackYPCOnline:feature/openai

Conversation

@JackYPCOnline
Copy link
Copy Markdown
Contributor

@JackYPCOnline JackYPCOnline commented Apr 30, 2026

Description

Amazon Bedrock's OpenAI-compatible endpoint (Mantle) at
https://bedrock-mantle.<region>.api.aws/v1 serves the Chat Completions and
Responses APIs plus Responses-only features like stateful conversations and
reasoning controls — capabilities Converse doesn't expose.

Reaching Mantle today means hand-rolling the plumbing: mint a bearer token
with aws-bedrock-token-generator
(or sign with SigV4), compute the regional base URL, and pass both into
OpenAIModel / OpenAIResponsesModel via client_args. This PR adds a
first-class bedrock_mantle_config kwarg to both classes so the Bedrock routing stops
leaking into application code.

Public API

from strands.models.openai import OpenAIModel
from strands.models.openai_responses import OpenAIResponsesModel

OpenAIModel(model_id="openai.gpt-oss-120b", bedrock_mantle_config={"region": "us-east-1"})

OpenAIResponsesModel(
    model_id="openai.gpt-oss-120b",
    stateful=True,
    params={"reasoning": {"effort": "medium"}},
    bedrock_mantle_config={"region": "us-east-1"},
)

Related Issues

Documentation PR

In-repo docs update covers the feature for Python. TypeScript tab in the
new section notes the pathway isn't yet supported on that SDK.

Type of Change

New feature

Testing

  • I ran hatch run prepare

Checklist

  • I have read the CONTRIBUTING document
  • I have added any necessary tests that prove my fix is effective or my feature works
  • I have updated the documentation accordingly
  • I have added an appropriate example to the documentation to outline the feature, or no new docs are needed
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 30, 2026

Codecov Report

❌ Patch coverage is 97.14286% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/strands/models/_openai_bedrock.py 95.23% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

Comment thread src/strands/models/_openai_bedrock.py Outdated
Comment thread src/strands/models/_openai_bedrock.py Outdated
Comment thread pyproject.toml
Comment thread src/strands/models/openai.py Outdated
Comment thread src/strands/models/_openai_bedrock.py Outdated
@github-actions
Copy link
Copy Markdown

Issue: This PR introduces a new public API surface (aws_config kwarg on two model classes, AwsConfig TypedDict) that customers will directly use. Per the API Bar Raising guidelines, this qualifies as a "moderate change" (new parameter on frequently-used classes with a new TypedDict customers interact with).

Suggestion: Add the needs-api-review label to this PR so an API reviewer can evaluate the public surface from a customer perspective. The PR description is already well-prepared for this review.

@github-actions
Copy link
Copy Markdown

Assessment: Request Changes

The feature design is well thought out and the PR description is excellent. However, there's a critical import issue that would break existing users of the sagemaker and litellm extras.

Review Categories
  • Critical: Top-level import of aws_bedrock_token_generator in _openai_bedrock.py breaks sagemaker and litellm users at import time since those extras don't include this dependency. Use a lazy import inside resolve_bedrock_client_args() instead.
  • API Design: AwsConfig TypedDict should use Required[str] for region to surface misconfiguration at type-check time, matching existing patterns (AnthropicConfig, GeminiConfig). PR should also have the needs-api-review label.
  • Robustness: provide_token failures will surface as opaque tracebacks — wrapping with context will improve debuggability. Duplicate region validation between __init__ and resolve_bedrock_client_args should be consolidated.

The integration test rewrite is a nice simplification and the per-request token minting is the right design for long-lived agents.

Comment thread src/strands/models/openai_responses.py Outdated
@github-actions
Copy link
Copy Markdown

Assessment: Approve (with minor suggestion)

All critical and important issues from the previous review have been addressed well. The lazy import, Required[str] typing, consolidated validation, error wrapping, and new test coverage all look good.

Remaining minor item
  • Docstring accuracy: Both __init__ docstrings still list ValueError: If aws_config is missing a region under Raises, but region validation now happens at resolve time (in _resolve_client_args), not at construction time. Minor, non-blocking.

Clean implementation with solid test coverage — nice work addressing the feedback.

@github-actions
Copy link
Copy Markdown

Assessment: Approve

All feedback from prior reviews has been fully addressed. The code is clean, well-documented, and ready to merge.

Verification of fixes
  • ✅ Lazy import in resolve_bedrock_client_args() — sagemaker/litellm safe
  • Required[str] for region in AwsConfig
  • ✅ Docstrings accurate — no misleading Raises sections
  • RuntimeError wrapping for provide_token failures
  • ImportError with actionable install guidance
  • ✅ Consolidated validation (single source in helper)
  • ✅ Test coverage for error paths
  • ✅ PR description accurately describes lazy import behavior

Comment thread src/strands/models/_openai_bedrock.py Outdated
Comment thread src/strands/models/_openai_bedrock.py Outdated
Comment thread src/strands/models/_openai_bedrock.py Outdated
Comment thread src/strands/models/_openai_bedrock.py
Comment thread src/strands/models/openai.py Outdated
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 1, 2026

Issue: The PR description's "Public API" section shows aws_config={"region": "us-east-1"} but the actual kwarg name in the code is bedrock_mantle_config. This will confuse reviewers and readers.

Suggestion: Update the PR description code snippets to use the actual parameter name:

OpenAIModel(model_id="openai.gpt-oss-120b", bedrock_mantle_config={"region": "us-east-1"})

Comment thread tests/strands/models/test_openai.py
Comment thread src/strands/models/_openai_bedrock.py Outdated
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 1, 2026

Assessment: Approve (with minor suggestions)

Good evolution from aws_config to bedrock_mantle_config — the name is more specific and the region resolution chain (explicit → boto_session → default boto3) mirrors BedrockModel's behavior, which is consistent for AWS users.

Minor items (non-blocking)
  • PR description: The "Public API" code snippet still shows aws_config instead of bedrock_mantle_config
  • Fail-fast validation: The base_url/api_key conflict check in client_args could be moved to __init__ for earlier feedback
  • Test coverage: test_explicit_region_wins_over_boto_session exists for OpenAIModel but not OpenAIResponsesModel (shared code, so low risk)

The rename, stricter validation, and region resolution chain are all improvements. Implementation is clean and well-tested.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 1, 2026

Assessment: Approve

The fail-fast validation for client_args conflicts is now at init time as suggested — good improvement. The PR description still shows aws_config in the first code snippet (OpenAIModel example) which should be bedrock_mantle_config, but this was flagged in the prior review and is non-blocking.

No new issues found. The implementation is clean and ready to merge.

@JackYPCOnline JackYPCOnline enabled auto-merge (squash) May 1, 2026 20:14
Comment thread src/strands/models/_openai_bedrock.py
@JackYPCOnline JackYPCOnline disabled auto-merge May 1, 2026 21:13
@JackYPCOnline JackYPCOnline merged commit a245e6d into strands-agents:main May 1, 2026
21 of 22 checks passed
@JackYPCOnline JackYPCOnline deleted the feature/openai branch May 1, 2026 21:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants